<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-24
  Time: 8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
    <div id="root">
            <ROW style="margin-top: 40px;">
                <i-col span="12" style="margin-left: 20px">
                    <i-form :label-width="80">
                        <form-item label="姓名">
                            <i-input v-model="user.anames"  disabled style="width: 500px"></i-input>
                        </form-item>
                        <form-item label="年龄">
                            <i-input  v-model="user.aage" disabled style="width: 500px"></i-input>
                        </form-item>
                        <form-item label="账号">
                            <i-input v-model="user.account" disabled style="width: 500px"></i-input>
                        </form-item>
                        <%--<form-item label="密码">--%>
                            <%--<i-input  v-model="user.password" disabled style="width: 500px"></i-input>--%>
                        <%--</form-item>--%>
                        <form-item label="手机号">
                            <i-input v-model="user.phone" disabled style="width: 500px"></i-input>
                        </form-item>
                        <form-item label="职位">
                            <i-input v-model="user.posi"  disabled style="width: 500px"></i-input>
                        </form-item>
                        <form-item label="生日">
                            <date-picker :value="2012-12-23" disabled placeholder="2019-1-1"  v-model="user.birthday" type="date" format="yyyy-MM-dd"/>
                        </form-item>
                    </i-form>






                </i-col>
                <i-col span="8">
                    <i-form :label-width="80">
                        <form-item label="上传头像">
                            <upload :show-upload-list=false action="user/uplaod" methods="post" :on-success="uploadasdasd"  name="attach">
                                <i-button icon="ios-cloud-upload">请选择...</i-button>
                            </upload>
                        </form-item>
                        <form-item label="头像">
                            <div style="border-radius: 100%;width: 350px;height: 350px;">
                                <img style="border-radius: 100%;width: 350px;height: 350px;" :src="user.img" alt=""/>
                            </div>
                        </form-item>
                    </i-form>
                </i-col>
            </ROW>

        <Row>
            <i-col span="6">
                <Divider orientation="left">修改密码</Divider>
                <i-form :label-width="120">
                    <form-item label="原先的密码">
                        <i-input type="password"  v-model="ypwd"></i-input>
                    </form-item>
                    <form-item label="新密码">
                        <i-input type="password"  v-model="xpwd"></i-input>
                    </form-item>
                    <form-item label="再次输入新密码">
                        <i-input type="password"  v-model="xpwds"></i-input>
                    </form-item>
                    <form-item>
                        <i-button type="primary" style="width: 100%" @click="updatepwd">确定</i-button>
                    </form-item>
                </i-form>
            </i-col>

            <i-col span="6" offset="2">
                <Divider orientation="left">手机验证修改密码</Divider>
                <i-form :label-width="120">
                    <form-item label="手机号">
                        <i-input v-model="shoujihao" style="width: 200px"></i-input>
                        <i-button :disabled="disacahs" @click="fasongyanzhengma">{{fasongdezhi}}</i-button>
                    </form-item>
                    <form-item label="验证码">
                        <i-input v-model="yanzhengma01"></i-input>
                    </form-item>
                    <form-item label="新密码">
                        <i-input type="password" v-model="xinmima"></i-input>
                    </form-item>
                    <form-item>
                        <i-button type="primary" style="width: 100%" @click="shoujihaoyanzhengde">确定</i-button>
                    </form-item>
                </i-form>
            </i-col>
        </Row>

    </div>
    <script>
        let _this = null;
        new Vue({
            el:"#root",
            data:{
                user:{},
                ypwd:"",
                xpwd:"",
                xpwds:"",
                shoujihao:"",//手机号
                yanzhengma01:"",//验证码---随机数
                yanzhengma02:"",//输入的验证码---随机数
                xinmima:"",//新的密码
                fasongdezhi:"发送验证码",
                bianNumber:60,
                disacahs:false,
                reg: /^1[3|4|5|7|8][0-9]{9}$/
            },
            methods:{
                serchAll(){
                   axios.get("users/atcurrentUser").then(({data})=>{
                       this.user = data;
                   })
                },
                uploadasdasd(resp){
                    iview.Message.info(resp.msg);
                    this.serchAll();
                },
                updatepwd(){
                    if(this.ypwd==""||this.xpwd==""||this.xpwds==""){
                        iview.Message.warning("不能为空!");
                        return;
                    }
                    if(this.xpwd.length<4){
                        iview.Message.warning("长度必须是大于3个字符!");
                        return;
                    }
                    if(this.xpwd!=this.xpwds){
                        iview.Message.warning("密码不匹配!");
                        return;
                    }
                    axios.get("/user/updatepwd?ypwd="+this.ypwd+"&pwdx="+this.xpwds).then(({data})=>{
                        console.log(data.msg)
                        iview.Modal.confirm({
                            title:"提示",
                            content:"修改成功!请重新登录",
                            onOk(){
                                if(data.msg=="1"){
                                    <%--top.parent.location.href="${pageContext.request.contextPath}/login.do";--%>
                                    top.parent.location.href="/login.do";
                                }
                             }
                        })
                    })
                },
                fasongyanzhengma(){
                    if (!(/^1[34578]\d{9}$/.test(this.shoujihao))) {
                        iview.Message.warning("请输入正确的手机号!");
                        return;
                    }
                    if(_this.user.phone!=_this.shoujihao){
                        iview.Message.warning("当前手机号不匹配,发送失败!");
                        return;
                    }
                    this.yanzhengma02 = Math.floor(Math.random()*500000+500000);
                    // this.yanzhengma01 = this.yanzhengma02;///////////////////////////////////////////////
                    var tingshi = setInterval(function () {
                        _this.bianNumber--;
                        _this.fasongdezhi = '获取中('+_this.bianNumber+')'
                        _this.disacahs = true;
                        if(_this.bianNumber<=0){
                            _this.fasongdezhi = "获取验证码";
                            _this.disacahs = false;
                            _this.bianNumber=60;
                            clearTimeout(tingshi);
                        }
                    },1000);
                    /////////////////////手机号发送进行的验证
                    axios.get("/user/yanzhenma?suijiNumber="+_this.yanzhengma02+"&shoujihao="+_this.shoujihao+"&as=翱翔医药系统").then(({data})=>{
                        iview.Message.info("发送成功!")
                    })
                },
                shoujihaoyanzhengde(){
                    //验证手机号
                    if (!(/^1[34578]\d{9}$/.test(this.shoujihao))) {
                    // if(this.reg.test(this.shoujihao)){
                        iview.Message.warning("请输入正确的手机号!");
                        return;
                    }
                    if(_this.yanzhengma01==null||_this.yanzhengma01==""){
                        iview.Message.warning("请输入验证码!");
                        return;
                    }
                    if(_this.yanzhengma01!= _this.yanzhengma02){
                        iview.Message.warning("验证码错误!");
                        return;
                    }
                    if(_this.xinmima.length<=3){
                        iview.Message.warning("密码长度大于3个字符!");
                        return;
                    }
                    axios.get("/user/updatespwd?m="+_this.xinmima+"&suijiNumber="+_this.yanzhengma02+"&shoujihao="+_this.shoujihao).then(({data})=>{
                        console.log(data.msg)
                        iview.Modal.warning({
                            title:"提示",
                            content:"修改成功!请重新登录",
                            onOk(){
                                // if(data.msg=="1"){
                                    top.parent.location.href="/login.do";
                                // }
                            }
                        })
                    })
                }
                // MyBatis_Maven_Shiro_SpringMvc_AliYunDuAPI_Echarts
            },
            mounted(){
                this.serchAll();
            },
            created(){
                _this = this;
            }
        })
    </script>
</body>
</html>
